package com.mt.course.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.mt.common.PagerInfo;
import com.mt.common.ServiceResult;
import com.mt.common.constants.BaseErrorConstants;
import com.mt.course.api.service.IServiceConfigService;
import com.mt.course.entity.ServiceConfigEntity;
import com.mt.course.service.model.ServiceConfigServiceModel;

@Service
public class ServiceConfigServiceImpl implements IServiceConfigService {
    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ServiceConfigServiceImpl.class);

    @Autowired
    private ServiceConfigServiceModel serviceConfigServiceModel;

    public ServiceResult<List<ServiceConfigEntity>> findList(Map<String, Object> params, PagerInfo<?> pagerInfo) {
        ServiceResult<List<ServiceConfigEntity>> result = null;
        try {
            result = serviceConfigServiceModel.selectList(params, pagerInfo);
        } catch (Exception e) {
            LOGGER.error("[ServiceConfigServiceImpl][findList]：query findList occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "查询列表错误");
        }
        return result;
    }

    public ServiceResult<ServiceConfigEntity> findInfo(Map<String, Object> params) {
        ServiceResult<ServiceConfigEntity> result = null;
        try {
            result = serviceConfigServiceModel.selectInfo(params);
        } catch (Exception e) {
            LOGGER.error("[ServiceConfigServiceImpl][findInfo]：query findInfo occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "查询详情错误");
        }
        return result;
    }

    public ServiceResult<Integer> doInsert(ServiceConfigEntity serviceConfigEntity) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = serviceConfigServiceModel.insert(serviceConfigEntity);
        } catch (Exception e) {
            LOGGER.error("[ServiceConfigServiceImpl][doInsert]：query doInsert occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "创建信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> doDeleteById(Integer serviceConfigId) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = serviceConfigServiceModel.deleteByPrimaryKey(serviceConfigId);
        } catch (Exception e) {
            LOGGER.error("[ServiceConfigServiceImpl][doDeleteById]：query doDeleteById occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "删除信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> doUpdate(ServiceConfigEntity serviceConfigEntity) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = serviceConfigServiceModel.updateByPrimaryKeySelective(serviceConfigEntity);
        } catch (Exception e) {
            LOGGER.error("[ServiceConfigServiceImpl][doUpdate]：query doUpdate occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "更新信息错误.");
        }
        return result;
    }
}
